<?php
namespace Textblast;

require_once 'connect.php';
require_once 'util/validate.php';


class User {

	protected $con;
	protected $db;

	function Add() {

	}

	function isMember($username, $password) {
		$user = array(false);
		$password = Validate::makeHash($password);

		try {
			$this->db = $this->con->open();

			if(Validate::withDomain($username)) {
				$params = preg_split('/\\\\\\\\/', $username);
				$params[] = $password;
				$this->proc = $this->db->prepare("CALL spIsAuthUserMember(?, ?, ?)");
			} else {
				$params = array($username, $password);
				$this->proc = $this->db->prepare("CALL spIsUserMember(?, ?)");
			}

			if($this->proc->execute($params) === true) {
				if($this->proc->rowCount() === 1) {
					$user[0] = true;
					$user[] = $this->proc->fetchAll();
				}
			}
		} catch (Exception $e) {
			$this->con->close();
		}
		$this->con->close();

		return $user;
	}

	function __construct() {
		//parent::__construct();
		$this->con = new Connect();
		
	}
}
?>